package com.tanhua.model.vo;

import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.mongo.Comment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author げっしょく
 * @date 2021/10/30
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SubjectVo implements Serializable {

    private String id;
    private String avatar;
    private String nickname;
    private String createDate;

    public static SubjectVo init(UserInfo userInfo, Comment comment) {
        Date date = new Date(comment.getCreated());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年M月d日 HH:mm:ss");
        String format = simpleDateFormat.format(date);
        SubjectVo subjectVo = new SubjectVo();
        subjectVo.setId(comment.getId().toHexString());
        subjectVo.setAvatar(userInfo.getAvatar());
        subjectVo.setNickname(userInfo.getNickname());
        subjectVo.setCreateDate(format);
        return subjectVo;
    }
}
